home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / hardware / kbdhand9 / key.asm < prev    next >
Assembly Source File  |  1994-06-15  |  8KB  |  219 lines

  1. ;******************************************************************************
  2. ;* INT9 keyboard handler #9 (32-bit)
  3. ;* by Lee Hamel (hamell@cs.pdx.edu)
  4. ;* June 15th, 1994
  5. ;*
  6. ;* All keyboard buffering code by James Ketrenos (ketrenoj@cs.pdx.edu)
  7. ;******************************************************************************
  8. .386P
  9.  
  10. PIC_CMD                 EQU     20h
  11. NONSPEC_EOI             EQU     20h
  12.  
  13. _data   segment dword public use32
  14. PUBLIC  _keys
  15.         _keys           db      256 dup (0)
  16. PUBLIC  _keynumpress
  17.         _keynumpress    db      0
  18. PUBLIC  _keylast
  19.         _keylast        db      0
  20. PUBLIC  _oldkeylast
  21.         _oldkeylast     db      0
  22.  
  23. toASCII                 db      0,27,'1234567890-=',14,15
  24.                         db      'qwertyuiop',0,0,13,0,'as'
  25.                         db      'dfghjkl',0,0,'''',0,0,'zxcv'
  26.                         db      'bnm',0,'./',0,0,0,' ',0,1,2,3,4,5
  27.                         db      6,7,8,9,10,0,0,24,25,26,'-',21,22,23,0,18
  28.                         db      19,20,16,17,0,0,0,11,12,0,0,0,0,0,0,0
  29.                         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  30.                         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  31.                         db      0,27,'!',0,'#',0,'%',0,0,0,0,0,0,0,14,15
  32.                         db      'QWERTYUIOP',0,0,13,0,'AS'
  33.                         db      'DFGHJKL:',0,'"',0,0,'ZXCV'
  34.                         db      'BNM',0,0,'?',0,0,0,' ',0,1,2,3,4,5
  35.                         db      6,7,8,9,10,0,0,24,25,26,'-',21,22,23,0,18
  36.                         db      19,20,16,17,0,0,0,11,12,0,0,0,0,0,0,0
  37.                         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  38.                         db      0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
  39. e0flag                  db      0
  40. oldint9off              dd      ?
  41. oldint9sel              dw      ?
  42. keyinst                 db      0
  43. keyhead                 db      0
  44. keytail                 db      0
  45. keybuffer               db      256 dup(0)
  46. keyrepeat               db      256 dup(0)
  47. _data   ENDS
  48.  
  49. _text   segment para public use32
  50.         assume cs:_text, ds:_data
  51.  
  52.  
  53. ;*****************************************************************************
  54. ;
  55. ; ClearKeys_ and GetKey_ routines by James Ketrenos (ketrenoj@cs.pdx.edu)
  56. ;
  57. ;*****************************************************************************
  58.  
  59.                         PUBLIC  ClearKeys_
  60. ClearKeys_              PROC
  61.                 push    bx
  62.         ;; *********************************************
  63.         ;; Clear the buffer by setting TAIL on HEAD
  64.         ;; *********************************************
  65.                 mov     bl,keyhead
  66.                 mov     keytail,bl
  67.                 mov     [_keylast],0
  68.                 pop     bx
  69.                 ret
  70. ClearKeys_              ENDP
  71.  
  72.                         PUBLIC  GetKey_
  73. GetKey_                 PROC
  74.                 push    eax ebx
  75.                 xor     eax,eax
  76.         ;; *********************************************
  77.         ;; Check to see if buffer is EMPTY
  78.         ;; *********************************************
  79.         movzx   ebx,keytail             ;; Point to the end of the buffer
  80.         cmp     bl,keyhead              ;; : and if it is equal to the front,
  81.         jz      GKDone                  ;; : then the buffer is empty, so wait.
  82.  
  83.         ;; *********************************************
  84.         ;; Get next key from KEYBOARD BUFFER
  85.         ;; *********************************************
  86.         mov     al,keybuffer[ebx]       ;; Fetch the ASCII Code
  87.         inc     [keytail]               ;; Increment the KeyTail
  88.                                         ;; : NOTE that it loops at bl==256
  89.                 cmp     al,1Bh          ; Esc
  90.                 jne     GKDone
  91.                 cmp     keyrepeat[1],2  ; dont want Esc repeating
  92.                 jb      GKDone
  93.                 xor     al,al
  94. GKDone:
  95.                 mov     [_keylast],al
  96.                 pop     ebx eax
  97.                 ret                     ;; Return to caller and all that stuff
  98. GetKey_                 ENDP
  99.  
  100.                         PUBLIC  Set_New_Int9_
  101. Set_New_Int9_           PROC
  102.                 cmp     [keyinst],1
  103.                 je      exitnew9
  104.  
  105.                 mov     [keyinst],1
  106.                 cli
  107.                 pushad
  108.                 push    ds es
  109.                 mov     eax,3509h
  110.                 int     21h
  111.                 mov     [oldint9off],ebx
  112.                 mov     [oldint9sel],es
  113.                 mov     eax,2509h
  114.                 mov     edx,offset New_Int9
  115.                 push    cs
  116.                 pop     ds
  117.                 int     21h
  118.                 pop     es ds
  119.                 popad
  120.                 sti
  121. exitnew9:       ret
  122. Set_New_Int9_           ENDP
  123.  
  124.                         PUBLIC  Set_Old_Int9_
  125. Set_Old_Int9_           PROC
  126.                 cmp     [keyinst],0
  127.                 je      exitold9
  128.  
  129.                 mov     [keyinst],0
  130.                 cli
  131.                 pushad
  132.                 push    ds
  133.                 mov     edx,[oldint9off]
  134.                 mov     ds,[oldint9sel]
  135.                 mov     eax,2509h
  136.                 int     21h
  137.                 pop     ds
  138.                 popad
  139.                 sti
  140. exitold9:       ret
  141. Set_Old_Int9_           ENDP
  142.  
  143. New_Int9                PROC
  144.                 push    eax ebx ecx ds
  145.                 mov     ax,_data
  146.                 mov     ds,ax
  147.  
  148.                 in      al,60h
  149.                 mov     ah,al
  150.  
  151. ; these 5 lines of code only necessary on XT's
  152. ;                in      al,61h
  153. ;                or      al,80h
  154. ;                out     61h,al
  155. ;                and     al,7Fh
  156. ;                out     61h,al
  157.  
  158. ;                pushfd                          ; this calls the BIOS handler
  159. ;                call    [oldint9pm]
  160.  
  161.                 cmp     ah,0E0h
  162.                 jae     e0flagset
  163.  
  164.                 movzx   ebx,ah
  165.                 and     bl,01111111b
  166.                 add     bl,[e0flag]
  167.                 mov     [e0flag],0
  168.  
  169.                 rol     ah,1
  170.                 jc      keyrelease
  171.  
  172. keypress:       mov     ah,1
  173.                 sub     ah,_keys[ebx]           ; old key status
  174.                 add     [_keynumpress],ah
  175.                 mov     _keys[ebx],1            ; key pressed
  176.                 mov     bh,_keys[2ah]           ; get left shift status
  177.                 or      bh,_keys[36h]           ; get right shift status
  178.                 ror     bh,1                    ; put in bit 7
  179.                 add     bl,bh                   ; final key value
  180.                 xor     bh,bh                   ; clear for index use
  181.                 mov     al,toASCII[ebx]         ; get translated value
  182.  
  183.         ;; *********************************************
  184.     ;; Check to see if buffer is FULL
  185.     ;; *********************************************
  186.         movzx   ecx,keyhead             ;; Point to the front of the buffer
  187.         inc     cl                      ;; : and if the next space places
  188.         cmp     cl,keytail              ;; : us on the end of the buffer,
  189.         jz      int9_done               ;; : then the buffer is full ...
  190.         dec     cl                      ;; : otherwise, we help fill it.
  191.  
  192.     ;; *********************************************
  193.     ;; Put key into KEYBOARD BUFFER (Adding scancode)
  194.     ;; *********************************************
  195.         mov     keybuffer[ecx],al       ;; Save the ASCII Code into buffer
  196.         inc     cl                      ;; Increment the KeyHead
  197.         mov     keyhead,cl              ;; : NOTE that it loops at bl==256
  198.         cmp     keyrepeat[ebx],2
  199.         je      int9_done
  200.         inc     keyrepeat[ebx]
  201.                 jmp     int9_done
  202.  
  203. keyrelease:
  204.                 dec     [_keynumpress]
  205.                 mov     _keys[ebx],0            ; key released
  206.                 mov     keyrepeat[ebx],0
  207.                 jmp     int9_done
  208.  
  209. e0flagset:      mov     [e0flag],128
  210. int9_done:      mov     al,NONSPEC_EOI
  211.                 out     PIC_CMD,al
  212.                 pop     ds ecx ebx eax
  213.                 iretd
  214. New_Int9                ENDP
  215.  
  216. _text           ENDS
  217.  
  218.                 END
  219.